package structurepattern.filter;

import java.util.ArrayList;
import java.util.List;

public class FilterPatternDemo {

	public static void main(String[] args) {
		List<Person> persons = new ArrayList<Person>();
		persons.add(new Person("Robert", "Male", "Single"));
		persons.add(new Person("John", "Male", "Married"));
		persons.add(new Person("Laura", "Female", "Married"));
		persons.add(new Person("Diana", "Female", "Single"));
		persons.add(new Person("Mike", "Male", "Single"));
		persons.add(new Person("Bobby", "Male", "Single"));
		
		Criteria male = new MaleCriteria();
		Criteria female = new FemaleCriteria();
		Criteria single = new SingleCriteria();
		Criteria singleMale = new AndCriteria(single, male);
		Criteria singleOrFemal = new OrCriteria(single, female);
		
		System.out.println("Males:");
		printPersons(male.meetCriteria(persons));
		System.out.println("Females:");
		printPersons(female.meetCriteria(persons));
		System.out.println("Single Males:");
		printPersons(singleMale.meetCriteria(persons));
		System.out.println("Single or Females:");
		printPersons(singleOrFemal.meetCriteria(persons));
	}
	
	static void printPersons(List<Person> persons) {
		for(Person person: persons) {
			System.out.println("Person: [ Name: " + person.getName() 
			+ ", Gender:" + person.getGender() 
			+ ", Marital Status: " 
			+ person.getMaritalStatus() + "]");
		}
	}
}
